package com.wavejo.reactor.web.controller;

import com.wavejo.reactor.pojo.User;
import com.wavejo.reactor.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

/**
 * @Author WaveHi
 * @Date 26/10/2021 下午 5:19
 * @Version 1.0
 * @Contact HJBWaveHi@163.com
 * @Description
 */
@RestController
public class UserController {

    @Autowired
    private UserService userService;

    @GetMapping("/user/{id}")
    public Mono<User> getData(@PathVariable Long id) {
        return userService.getUser(id);
    }

    @GetMapping("/user/getAll")
    public Flux<User> getAll() {
        return userService.getAllUser();
    }

    @GetMapping("/user/saveUser")
    public Mono<Void> add(@RequestBody User user) {
        Mono<User> userMono = (Mono<User>) Mono.just(user);
        return userService.addUser(userMono);
    }
}
